package com.tspark.tspark1.zoo.result;

import lombok.Data;

/**
 * 统一封装类 作为返回结果
 * 一般情况调用fail和success即可
 *      code为0   成功
 *      code不为0 失败 (默认是-1)
 */
@Data

public class Result<T> {

    private int code;
    private String message;
    private T data;

    public Result(T data) {
        this.code = 0;
        this.message = "success";
        this.data = data;
    }


    public Result(int code, String message) {
        this.code = code;
        this.message = message;
        this.data = null;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(data);
    }

    public static <T> Result<T> fail(String message) {
        return new Result<>(-1, message);
    }

    public static <T> Result<T> fail(int code, String message) {
        return new Result<>(code, message);
    }
}

